<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * AiTuPu
 *
 * An open source social sharing platform
 *
 * @package		AiTuPu
 * @author		Duobianxing Studio Dev Team
 * @copyright	Copyright © 2011 - 2012, Duobianxing, Inc.
 * @license		http://duobianxing.com/doc/license.html
 * @link		http://duobianxing.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * AiTuPu Register Controller
 *
 *
 * @package		AiTuPu
 * @subpackage	Controllers
 * @category	Controllers
 * @author		Duobianxing Studio Dev Team
 * @link		http://duobianxing.com/doc/index.html
 */

class Moneychange extends MY_Controller {

	public function __construct() {
		parent::__construct();
	}

	public function index()
	{
		$this->load->model('PayType_model');
		$PayTypes = $this->PayType_model->get_All();
		$data['PayTypes']=$PayTypes;
		$this->output("common/layout", array('body'=>'Moneychange/index'),$data);
		
	}
	
	public function post()
	{
		if($this->user_model->get_usersession()) {
			redirect("Moneychange/index1");
		}else{
			//exit('Acess denied!');
			redirect('register/index');
		}
	}	
	
	public function index1()
	{
		$this->load->model('PayType_model');
		$PayTypes = $this->PayType_model->get_All();
		$data['PayTypes']=$PayTypes;
		$this->output("common/layout", array('body'=>'Moneychange/index1'),$data);
		
	}

	public function RemittancePost()
	{
		$this->load->library('form_validation');	

		$Remittance = $this->input->post('Remittance');
		$Mobile = $this->input->post('Mobile');
		$BelongPayType = $this->input->post('BelongPayType');
		$AccountNo = $this->input->post('AccountNo');
		$Name = $this->input->post('Name');
		$ReceiptAmount = $this->input->post('ReceiptAmount');
		$MaybeTime = $this->input->post('MaybeTime');
		
		//设置验证规则
		$this->form_validation->set_rules('Remittance', '汇款金额', 'required|max_length[10]|numeric|greater_than[0]');
		$this->form_validation->set_rules('Mobile', '手机号码', 'required|max_length[15]|numeric');
		$this->form_validation->set_rules('BelongPayType', '收款方式', 'required|numeric|greater_than[0]');
		$this->form_validation->set_rules('AccountNo', '收款账号', 'required|max_length[30]');
		$this->form_validation->set_rules('Name', '开户姓名', 'required|max_length[15]');
		$this->form_validation->set_rules('ReceiptAmount', '收款金额', 'required|max_length[8]|numeric|greater_than[0]');
		$this->form_validation->set_rules('MaybeTime', '到账时间', 'required|max_length[8]|numeric|greater_than[0]');
		
		//设置规则提示信息
		$this->form_validation->set_message('numeric', '只能输入数字！');
		$this->form_validation->set_message('required', '不能为空！');
		$this->form_validation->set_message('integer', '只能是整数！');
		$this->form_validation->set_message('greater_than', '必须大于0！');
		
		//错误定界符
		$this->form_validation->set_error_delimiters('', '');
		
		if ($this->form_validation->run() == FALSE)
		{
			$Remittance_Error =  form_error('Remittance');//分别显示错误,在页面中
			$Mobile_Error =  form_error('Mobile');//分别显示错误,在页面中
			$AccountNo_Error =  form_error('AccountNo');//分别显示错误,在页面中
			$Name_Error =  form_error('Name');//分别显示错误,在页面中
			$ReceiptAmount_Error =  form_error('ReceiptAmount');//分别显示错误,在页面中
			$MaybeTime_Error =  form_error('MaybeTime');//分别显示错误,在页面中
			
			//echo validation_errors();//显示全部错误
			$data['Remittance_Error'] = $Remittance_Error;
			$data['Mobile_Error'] = $Mobile_Error;
			$data['AccountNo_Error'] = $AccountNo_Error;
			$data['Name_Error'] = $Name_Error;
			$data['ReceiptAmount_Error'] = $ReceiptAmount_Error;
			$data['MaybeTime_Error'] = $MaybeTime_Error;
			
			$this->load->model('PayType_model');
			$PayTypes = $this->PayType_model->get_All();
			$data['PayTypes']=$PayTypes;
		
			$this->output("common/layout", array('body'=>'Moneychange/index1'),$data);
			//echo 'yyyyyyyyyy';
		}
		else
		{
			$this->load->model('Remittance_model');
			$data = array(
               'Remittance' => $Remittance ,
               'Mobile' => $Mobile ,
               'BelongPayType' => $BelongPayType,
			   'AccountNo' => $AccountNo,
			   'Name' => $Name,
			   'ReceiptAmount' => $ReceiptAmount,
			   'MaybeTime' => $MaybeTime
            );
			
			if($Id==0)
				$this->Remittance_model->Add($data);
			else
				$this->Remittance_model->Update($Id,$data);	
			
			//$success = '输入成功！';
			//$data['success']=$success;
			//$this->load->view('admin/SetPayType',$data);
			echo 'ok';
		}	
	}
}